package chai.ningning.schedule;

public class SleepTest {

    static class SleepThread implements Runnable{

        private boolean sleep;
        private String name;

        public SleepThread(String name,boolean sleep) {
            this.name = name;
            this.sleep = sleep;
        }

        @Override
        public void run() {
            Thread t = Thread.currentThread();

            try {
                for (int i = 0; i < 5; i++) {
                    System.out.println(t + " : " + i);
                    if (sleep) {
                        Thread.sleep(5000);
                    }
                }
            }catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {

        Runnable runnable1 = new SleepThread("First",false);
        Runnable runnable2 = new SleepThread( "SECOND" , true );
        Runnable runnable3 = new SleepThread( "THIRD" , false );
        Runnable runnable4 = new SleepThread( "FOURTH" , false );

        Thread first = new Thread(runnable1);
        Thread second = new Thread(runnable2);
        Thread third = new Thread(runnable3);
        Thread fourth = new Thread(runnable4);

        first.start();
        second.start();
        third.start();
        fourth.start();
    }
}
